3 Andrés Mejía-Posada (andmej@gmail.com)
27 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
28 #define For(i, a, b) for (int i=(a); i<(b); ++i)
29 #define D(x) cout << #x " is " << x << endl
32 bool good
[1005][1005];
44 for (int i
=0; i
<n
; ++i
){
47 good
[i
][i
+1] = s
[i
] == s
[i
+1];
50 for (int d
=2; d
<=n
; ++d
){
51 for (int i
=0, j
; (j
= i
+ d
)<n
; ++i
){
52 good
[i
][j
] = good
[i
+1][j
-1] && (s
[i
] == s
[j
]);
57 for (int i
=1; i
<n
; ++i
){
60 for (int j
=i
; j
>0; --j
){
63 dp
[i
] = min(dp
[i
], dp
[j
-1] + 1);
67 cout
<< dp
[n
-1] << endl
;